#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


typedef long long ll;
int main1() {
    int n; cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    vector<ll> dp1(n + 1), dp2(n + 1);
    for (int i = 1; i <= n; i++)
    {
        dp1[i] = dp2[i - 1] + a[i - 1];
        dp2[i] = max(dp2[i - 1], dp1[i - 1]);
    }

    cout << max(dp1[n], dp2[n]);

    return 0;
}

int main2()
{
    string str;
    cin >> str;

    int _min = -1;

    if (str.size() == 2 && str[0] == str[1] || str[0] == str[1])
    {
        _min = 2;
    }
    else
    {
        for (int i = 2; i < str.size(); i++)
        {
            if (str[i] == str[i - 1])
            {
                _min = 2;
                break;
            }

            if (str[i] == str[i - 2])
            {
                _min = 3;
            }
        }
    }

    cout << _min << endl;
    return 0;
}

void Test1()
{

}

int main()
{
    int _max = INT_MIN;
    int _min = INT_MAX;
    int max_sum = 0;

    int n, p; cin >> n >> p;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i] > _max) { _max = v[i]; }
        if (v[i] < _min) { _min = v[i]; }
    }

    for (int i = _min; i <= _max; i++)
    {
        int count = 0;
        for (int j = 0; j < v.size(); j++)
        {
            if (abs(v[j] - i) <= p)
            {
                count++;
            }
        }
        if (count > max_sum) { max_sum = count; }
    }

    cout << max_sum << endl;
    return 0;
}

int main()
{

	return 0;
}